package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.UserTest;
import com.ruoyi.system.service.IUserTestService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 测试用户Controller
 * 
 * @author ruoyi
 * @date 2022-08-06
 */
@RestController
@RequestMapping("/usertest")
public class UserTestController extends BaseController
{
    @Autowired
    private IUserTestService userTestService;

    /**
     * 查询测试用户列表
     */
    @RequiresPermissions("system:usertest:list")
    @GetMapping("/list")
    public TableDataInfo list(UserTest userTest)
    {
        startPage();
        List<UserTest> list = userTestService.selectUserTestList(userTest);
        return getDataTable(list);
    }

    /**
     * 导出测试用户列表
     */
    @RequiresPermissions("system:usertest:export")
    @Log(title = "测试用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserTest userTest)
    {
        List<UserTest> list = userTestService.selectUserTestList(userTest);
        ExcelUtil<UserTest> util = new ExcelUtil<UserTest>(UserTest.class);
        util.exportExcel(response, list, "测试用户数据");
    }

    /**
     * 获取测试用户详细信息
     */
    @RequiresPermissions("system:usertest:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userTestService.selectUserTestById(id));
    }

    /**
     * 新增测试用户
     */
    @RequiresPermissions("system:usertest:add")
    @Log(title = "测试用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserTest userTest)
    {
        return toAjax(userTestService.insertUserTest(userTest));
    }

    /**
     * 修改测试用户
     */
    @RequiresPermissions("system:usertest:edit")
    @Log(title = "测试用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserTest userTest)
    {
        return toAjax(userTestService.updateUserTest(userTest));
    }

    /**
     * 删除测试用户
     */
    @RequiresPermissions("system:usertest:remove")
    @Log(title = "测试用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userTestService.deleteUserTestByIds(ids));
    }
}
